<?php
namespace app\index\controller;
use think\Db;
class Base extends \think\Controller
{
    public $userinfo = [];
    public $sys = [];
    public function __construct(){
        parent::__construct();
        $this->_checkLogin();
    }
    /**
     * 验证登录
     */
    private function _checkLogin(){
        //判断登陆
        if(cookie('phone')){
            $userinfo = Db::name('user')->where('phone',cookie('phone'))->find();
        }else{
            $userinfo = [];
        }
        $this->userinfo = $userinfo;
        $this->assign('userinfo', $this->userinfo);
        \my\G::set( $this->userinfo );

        //判断路由
        if(com_controller()=='publics')
            return;
        if(!$this->userinfo)
            r(url('publics/login'));
    }
}
